
package edu.upf.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>This class is a log system utility created to make easy logging in the
 * application. It has different methods depending on the debug level or type
 * </p>
 * 
 * @author     netjois
 */
public class LogSystem implements Definitions {

    private static Log log;
    private static Log console;

    /**
     * Log utility constructor
     * @param className
     */
    public LogSystem(java.lang.Class className){
        log=LogFactory.getLog(className);
        console = LogFactory.getLog("edu.upf.console");
    }

    /**
     * Method for printing messages with log debug level.
     *
     * @param debugLog 
     */
    public void addDebugLog(String debugLog){
        if (log.isDebugEnabled()) {
            log.debug(debugLog);
        }
    }

    /**
     * Method for printing messages with log info level.
     * @param debugLog
     */
    public void addInfoLog(String debugLog){
        log.info(debugLog);
    }

    /**
     * Logger created to print status messages about components
     * in a log debug level.
     * 
     * @param boolLog 
     * @param status
     */
    public void addBoolDebug(String boolLog, boolean status){
        if (log.isDebugEnabled()) {
            StringBuffer buffer = new StringBuffer(boolLog);
            if(status){
                buffer.append(OK);
            }
            else{
                buffer.append(KO);
            }
            log.debug(buffer);
        }
    }

    /**
     * Logger created to print messages of this class.
     * This logger replaces <code>System.out.println</code>
     *
     * @param info
     */
    public void console(String info){
        console.info(info);
    }

    /**
     * Logger created to log a message with error log level.
     * 
     * @param info
     */
    public void error(String info){
        log.error(info);
    }

    /**
     * Logger created to log a message with error log level.
     * 
     * @param info
     * @param exception
     */
    public void error(String info, Throwable exception){
        log.error(console, exception);
    }

}
